package com.example.permissionsystem1_1.businessFunction.controller.impl;

import com.example.permissionsystem1_1.businessFunction.controller.converter.RoleFunctionControllerConverter;
import com.example.permissionsystem1_1.businessFunction.controller.converter.UserRoleControllerConverter;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.roleFunctionReqDto.RoleFunctionSelectAllFunctionsByRoleIdReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.roleFunctionReqDto.RoleFunctionSetRoleFunctionRelationReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.userRoleReqDto.UserRoleSelectAllRolesByUserIdReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.reqDto.userRoleReqDto.UserRoleSetUserRoleRelationReqDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.roleFunctionRspDto.RoleFunctionSelectAllFunctionsByRoleIdRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.roleFunctionRspDto.RoleFunctionSetRoleFunctionRelationRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.userRoleRspDto.UserRoleSelectAllRolesByUserIdRspDto;
import com.example.permissionsystem1_1.businessFunction.controller.entity.rspDto.userRoleRspDto.UserRoleSetUserRoleRelationRspDto;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.roleFunctionReqModel.RoleFunctionSelectAllFunctionsByRoleIdReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.roleFunctionReqModel.RoleFunctionSetRoleFunctionRelationReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.userRoleReqModel.UserRoleSelectAllRolesByUserIdReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.reqModel.userRoleReqModel.UserRoleSetUserRoleRelationReqModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.roleFunctionRspModel.RoleFunctionSelectAllFunctionsByRoleIdRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.roleFunctionRspModel.RoleFunctionSetRoleFunctionRelationRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.userRoleRspModel.UserRoleSelectAllRolesByUserIdRspModel;
import com.example.permissionsystem1_1.businessFunction.service.entity.rspModel.userRoleRspModel.UserRoleSetUserRoleRelationRspModel;
import com.example.permissionsystem1_1.businessFunction.service.interfaces.RoleFunctionService;
import com.example.permissionsystem1_1.businessFunction.service.interfaces.UserRoleService;
import com.example.permissionsystem1_1.common.businessFunction.BaseController;
import com.example.permissionsystem1_1.common.util.RspResult;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 角色-功能类
 * 后面这里的基础接口方法,都应该抽取成公共方法放到Base类中或者是用代码生成器生成模板代码(而不需要手写)
 */
@RestController
@RequestMapping("/roleFunction")
@ApiModel("角色-功能")
public class RoleFunctionController extends BaseController {
    @Autowired
    private RoleFunctionService roleFunctionService;

    @ApiOperation(value = "根据角色id查询全部功能信息", notes = "根据角色id查询全部功能信息", httpMethod = "POST")
    @RequestMapping(value = "/selectAllFunctionsByRoleId",method = RequestMethod.POST)
    public RspResult<RoleFunctionSelectAllFunctionsByRoleIdRspDto> selectAllFunctionsByRoleId(@Validated @RequestBody RoleFunctionSelectAllFunctionsByRoleIdReqDto reqDto){
        RoleFunctionSelectAllFunctionsByRoleIdReqModel reqModel= RoleFunctionControllerConverter.convertDtoToModel(reqDto);
        RoleFunctionSelectAllFunctionsByRoleIdRspModel rspModel=roleFunctionService.selectAllFunctionsByRoleId(reqModel);
        RoleFunctionSelectAllFunctionsByRoleIdRspDto rspDto=RoleFunctionControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }

    @ApiOperation(value = "设置角色与功能的关联关系", notes = "设置角色与功能的关联关系", httpMethod = "POST")
    @RequestMapping(value = "/setRoleFunctionRelation",method = RequestMethod.POST)
    public RspResult<RoleFunctionSetRoleFunctionRelationRspDto> setRoleFunctionRelation(@Validated @RequestBody RoleFunctionSetRoleFunctionRelationReqDto reqDto){
        RoleFunctionSetRoleFunctionRelationReqModel reqModel= RoleFunctionControllerConverter.convertDtoToModel(reqDto);
        RoleFunctionSetRoleFunctionRelationRspModel rspModel=roleFunctionService.setRoleFunctionRelation(reqModel);
        RoleFunctionSetRoleFunctionRelationRspDto rspDto=RoleFunctionControllerConverter.convertModelToDto(rspModel);
        return returnRspResult(rspDto);
    }


}
